<head>
    <title>编辑项目信息</title>
    <link href="/lego/static/css/bootstrap.css" rel="stylesheet"/>
    <link href="/lego/static/css/header.css" rel="stylesheet"/>
    <link href="/lego/static/css/xcConfirm.css" rel="stylesheet"/>
    <script src="/lego/static/js/jquery.1.11.3.min.js"/></script>
    <script src = "/lego/static/js/bootstrap.js" ></script>
    <script src="/lego/static/js/underscore-min.js"></script>
    <script src="/lego/static/js/common.js"></script>
    <script src="/lego/static/js/xcConfirm.js"></script>
    <script type="text/javascript">
        $(function () {
            //选择团队下拉框初始数据
            $.ajax({
                url: '/lego/getJoinedTeamList',
                type: 'GET',
                async: false,//先加载完团队下拉初始框,再给团队赋初始值
                success: function (data) {
                    if (data && data.code == 200) {
                        $('#teamDiv').html(_.template($('#selectTeam_template').html())({
                            data: data.data
                        }));
                    }
                }
            });

            initData();

            $("#editProjectBtn").click(function(){
                //参数校验
                var formJson = $('#projectForm').toJSON();
                var teamId = formJson['teamId'];
                var projectName = formJson['projectName'];
                var env = formJson['env'];
                var ip = formJson['ip'];
                var port = formJson['port'];
                if(teamId == ""){
                    window.wxc.xcConfirm("请选择项目所属团队!!!", window.wxc.xcConfirm.typeEnum.warning);
                    return;
                }
                if(projectName == ""){
                    window.wxc.xcConfirm("项目名称不能为空!!!", window.wxc.xcConfirm.typeEnum.warning);
                    return;
                }
                if(env == ""){
                    window.wxc.xcConfirm("请选择环境!!!", window.wxc.xcConfirm.typeEnum.warning);
                    return;
                }
                if(ip == ""){
                    window.wxc.xcConfirm("环境对应的ip不能为空!!!", window.wxc.xcConfirm.typeEnum.warning);
                    return;
                }
                if(port == ""){
                    window.wxc.xcConfirm("环境对应的端口不能为空!!!", window.wxc.xcConfirm.typeEnum.warning);
                    return;
                }
                $.ajax({
                    url: '/lego/updateProject',
                    type: 'POST',
                    data:$("#projectForm").toJSONString(),
                    contentType:'application/json;charset=UTF-8',
                    success: function (data) {
                        if (data && data.code == 200) {
                            if(data.msg == "更新成功"){
                                window.wxc.xcConfirm(data.msg, window.wxc.xcConfirm.typeEnum.success);
                            }else {
                                window.wxc.xcConfirm(data.msg, window.wxc.xcConfirm.typeEnum.error);
                            }
                        }
                    }
                });
            });
        });

        function initData(){
            var projectId = $("#projectId").val();
            $.ajax({
                url: '/lego/getProjectDetail',
                type: 'GET',
                data:{"projectId":projectId},
                success: function (data) {
                    if (data && data.code == 200) {
                        $("#teamId").val(data.data.teamId);
                        $("#projectName").val(data.data.projectName);
                        $("#env").val(data.data.env);
                        $("#ip").val(data.data.ip);
                        $("#port").val(data.data.port);
                    }
                }
            });
        }
    </script>
</head>
<body>
    <#include "../navigationBar.ftl">
    <header class="jumbotron subhead" id="overview">
        <div class="container">
            <h1>项目信息管理</h1>
        </div>
    </header>

    <form method="post" action="" class="form-horizontal" id="projectForm">
        <div class="row">
            <label for="projectId" class="col-sm-4 control-label">项目编号</label>
            <div class="col-sm-4">
                <input type="text" class="form-control " readonly="readonly" name="projectId" id="projectId" value="${projectId}">
            </div>
        </div>
        <div class="row">
            <label for="teamId" class="col-sm-4 control-label">团队</label>
            <div class="col-sm-4" id="teamDiv"></div>
            <#include "../common/template.ftl">
        </div>
        <div class="row">
            <label for="projectName" class="col-sm-4 control-label">项目名称</label>
            <div class="col-sm-4">
                <input type="text" class="form-control" name="projectName" id="projectName">
            </div>
        </div>
        <div class="row">
            <label for="env" class="col-sm-4 control-label">环境</label>
            <div class="col-sm-4">
                <select name="env" class="form-control" id="env">
                    <option value="LIANTIAO">联调环境</option>
                    <option value="CI">ci环境</option>
                    <option value="YANLIAN">演练环境</option>
                    <option value="ONLINE">线上环境</option>
                </select>
            </div>
        </div>
        <div class="row">
            <label for="ip" class="col-sm-4 control-label">IP</label>
            <div class="col-sm-4">
                <input type="text" class="form-control" name="ip" id="ip">
            </div>
        </div>
        <div class="row">
            <label for="port" class="col-sm-4 control-label">端口</label>
            <div class="col-sm-4">
                <input type="text" class="form-control" name="port" id="port">
            </div>
        </div>

        <div class="text-center" style="margin-top: 15px">
            <button class="btn btn-success" type="button" id="editProjectBtn">
                <span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存
            </button>
            <a class="btn btn-primary" href="/lego/projectListIndex">
                <span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span>返回列表
            </a>
        </div>
    </form>
</body>
